********************************************************************************
* Replication file: "Creating crowny capitalists"
* June 24, 2019
* Contact: bernhard.reinsberg@glasgow.ac.uk
********************************************************************************

***********************************************************************  
* Table 3: ICVS analysis 
***********************************************************************

* Data

  use "Replication_ICVS", clear
  g L1lngdppc=ln(L1gdppc_WDI)
  g L1lnpop=ln(L1unna_pop)
  g L2lngdppc=ln(L2gdppc)
  g L1lnodapc=ln(1.182+L1oda)

  lab var iD0080 "High-status neighborhood (%)"
  g HighNeigh=iD0080*100
  lab var iP00100 "Police does good job (%)" 
  g PoliceGood=iP00100*100
  lab var iS0020 "Feel safe in dark (%)"
  g FeelSafe=iS0020*100
  lab var cri1 "Assaults (%)" 
  g Assaults=cri1*100
  lab var cri2 "Fraud (%)"
  g Fraud=cri2*100
  su Fraud Assaults FeelSafe PoliceGood HighNeigh

  lab var iC14D301 "Easier to find corrupt official (%)"
  lab var iC14D302 "Easier to get fair treatment (%)"
  * available after 2000 (whereas cor1 after 1994)

  global S  FeelSafe PoliceGood HighNeigh
  global X1 L1lngdppc L1p_polity2 L1p_durable L1pop_urb
  global X2 $X1 L1p_durable L1min_gdp L1lnodapc
  *global Z L2IMFcum L2unsc L2s_unga L2reserves L2lngdppc L2gdp_growth L2debtser_gni dy_col _Iyear*
  global Z L2IMFcum L2s_unga L2lngdppc _Iyear*
  global Z2 L2IMFcum L2s_unga L2lngdppc L2reserves L2fh _Iyear*

  qui xi:reg cor1 i.incid i.regid i.cid i.year
  cmp setup 
  replace cor1=100*cor1
  lab var cor1 "Corruption (%)"

  
* Descriptive statistics  
  
  ** Table A1 - ICVS **
  qui estpost summarize cor1 L1IMFnn L1SCB L1QCB $X1 L2IMFcum L2s_unga L2lngdppc L2reserves $S Fraud  if NonMis>1 
  esttab, cells("count mean sd min max") noobs replace label   

  
  ** Table B14 ** 
  corr cor1 L1IMFnn L1SCB L1QCB $X1 $S Fraud if NonMis>1 

  
  
* FE analysis

  xtreg cor1 L1IMFnn if NonMis>1, fe 
  xtreg cor1 L1IMFnn _Iyear* if NonMis>1, fe 

  qui xtreg cor1 L1SCB L1QCB L1IMFnn _Iyear* if NonMis>1, fe 
  est store fe11
  qui xtreg cor1 L1SCB L1QCB L1IMFnn $X1 _Iyear* if NonMis>1, fe 
  est store fe12 
  qui xtreg cor1 L1SCB L1QCB L1IMFnn $S _Iyear* if NonMis>1, fe 
  est store fe13 
  qui xtreg cor1 L1SCB L1QCB L1IMFnn $X1 $S _Iyear* if NonMis>1, fe 
  est store fe14
  qui xtreg cor1 L1SCB L1QCB L1IMFnn $X1 $S Fraud _Iyear* if NonMis>1, fe 
  est store fe15

  
* Selection-corrected analysis

  qui treatreg cor1 L1IMFnn _Icid* _Iyear* if NonMis>1, treat(L1IMFnn=$Z) twostep hazard(imr) 
  drop imr 
  
  mat r2p=J(2,8,0)
 
  qui treatreg cor1 L1IMFnn L1SCB L1QCB _Icid* _Iyear* if NonMis>1, treat(L1IMFnn=$Z) twostep hazard(imr)
  qui reg cor1 L1IMFnn L1SCB L1QCB imr _Iyear* _Icid* if NonMis>1, ro
  est store he11
  mat r2p[2,1]=e(r2_a)
  drop imr 
  qui probit L1IMFnn $Z
  mat r2p[1,1]=e(r2_p)
  
  qui treatreg cor1 L1IMFnn L1SCB L1QCB $X1 _Icid* _Iyear* if NonMis>1, treat(L1IMFnn=$Z) twostep hazard(imr)
  qui reg cor1 L1IMFnn L1SCB L1QCB $X1 imr _Iyear* _Icid* if NonMis>1, ro
  drop imr 
  est store he12 
  mat r2p[2,2]=e(r2_a)
  qui probit L1IMFnn $Z
  mat r2p[1,2]=e(r2_p)
  
  qui treatreg cor1 L1IMFnn L1SCB L1QCB $X1 $S _Icid* _Iyear* if NonMis>1, treat(L1IMFnn=$Z) twostep hazard(imr)
  qui reg cor1 L1IMFnn L1SCB L1QCB $X1 $S imr _Iyear* _Icid* if NonMis>1, ro
  drop imr 
  est store he13 
  mat r2p[2,3]=e(r2_a)
  qui probit L1IMFnn $Z
  mat r2p[1,3]=e(r2_p)
  
  qui treatreg cor1 L1IMFnn L1SCB L1QCB $X1 $S Fraud _Icid* _Iyear* if NonMis>1, treat(L1IMFnn=$Z) twostep hazard(imr)
  qui reg cor1 L1IMFnn L1SCB L1QCB $X1 $S Fraud imr _Iyear* _Icid* if NonMis>1, ro
  drop imr 
  est store he14
  mat r2p[2,4]=e(r2_a)
  qui probit L1IMFnn $Z
  mat r2p[1,4]=e(r2_p)
  
  qui treatreg cor1 L1IMFnn L1SCB L1QCB _Icid* _Iyear* if NonMis>1, treat(L1IMFnn=$Z2) twostep hazard(imr)
  qui reg cor1 L1IMFnn L1SCB L1QCB imr _Iyear* _Icid* if NonMis>1, ro  
  est store he15
  mat r2p[2,5]=e(r2_a)
  drop imr 
  qui probit L1IMFnn $Z2
  mat r2p[1,5]=e(r2_p)
  
  qui treatreg cor1 L1IMFnn L1SCB L1QCB $X1 _Icid* _Iyear* if NonMis>1, treat(L1IMFnn=$Z2) twostep hazard(imr)
  qui reg cor1 L1IMFnn L1SCB L1QCB $X1 imr _Iyear* _Icid* if NonMis>1, ro
  drop imr 
  est store he16 
  mat r2p[2,6]=e(r2_a)
  qui probit L1IMFnn $Z2
  mat r2p[1,6]=e(r2_p)
  
  qui treatreg cor1 L1IMFnn L1SCB L1QCB $X1 $S _Icid* _Iyear* if NonMis>1, treat(L1IMFnn=$Z2) twostep hazard(imr)
  qui reg cor1 L1IMFnn L1SCB L1QCB $X1 $S imr _Iyear* _Icid* if NonMis>1, ro 
  drop imr 
  est store he17 
  mat r2p[2,7]=e(r2_a)
  qui probit L1IMFnn $Z2
  mat r2p[1,7]=e(r2_p)
  
  qui treatreg cor1 L1IMFnn L1SCB L1QCB $X1 $S Fraud _Icid* _Iyear* if NonMis>1, treat(L1IMFnn=$Z2) twostep hazard(imr)
  qui reg cor1 L1IMFnn L1SCB L1QCB $X1 $S Fraud imr _Iyear* _Icid* if NonMis>1, ro
  drop imr 
  est store he18
  mat r2p[2,8]=e(r2_a)
  qui probit L1IMFnn $Z2
  mat r2p[1,8]=e(r2_p)
  
  
  ** Table 3 **

  estout fe11 fe14 fe15 he11 he13 he14 he15 he17 he18, starlevels(* .1 ** .05 *** .01) cells(b(star fmt(3)) se(par fmt(3))) stats(r2_w N, fmt(%7.3f %7.0f)) drop(_cons *year* _I*) keep() order(*SC* *QC* L1IMFnn imr)
  di "Additional diagnostics:"
  mat li r2p
  
